package com.dongdongshop.service.impl;

import com.dongdongshop.common.PageResult;
import com.dongdongshop.mapper.TbItemCatMapper;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbGoodsDesc;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.pojo.TbItemCatExample;
import com.dongdongshop.service.TbItemCatService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class TbItemCatServiceImpl implements TbItemCatService {
    @Resource
    private TbItemCatMapper tbItemCatMapper;

    @Override
    public PageResult<TbItemCat> selectInfoParentIdServer(TbItemCat itemCat, Long parentId, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbItemCat> list = getItemCatByParentId(parentId);
        PageInfo<TbItemCat> page = new PageInfo<>(list);
        PageResult<TbItemCat> pageResult = new PageResult<>(page.getTotal(),page.getList());
        return pageResult;
    }

    @Override
    public TbItemCat selectByParentId(Long parentId) {
        TbItemCat tbItemCats = tbItemCatMapper.selectByPrimaryKey(parentId);
        return tbItemCats;
    }

    @Override
    public int addItemcat(TbItemCat tbItemCat) {
        int i = tbItemCatMapper.insertSelective(tbItemCat);
        return i;
    }

    @Override
    public TbItemCat getSelectItemcatById(Long id) {
        TbItemCat tbItemCat = tbItemCatMapper.selectByPrimaryKey(id);
        return tbItemCat;
    }

    @Override
    public int getUpdateItemcat(TbItemCat tbItemCat) {
        int i = tbItemCatMapper.updateByPrimaryKeySelective(tbItemCat);
        return i;
    }

    @Override
    public List<TbItemCat> getItemCatByParentId(Long parentId) {
        TbItemCatExample example = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        List<TbItemCat> list = tbItemCatMapper.selectByExample(example);
        return list;
    }

    @Override
    public List<TbItemCat> selectAll() {
        return tbItemCatMapper.selectByExample(null);
    }
}
